package com.ly.pj.ajax.controller;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
//@RequestMapping("/")
public class AjaxController {

    private List<String> list=new ArrayList<>();//假设这是一个存储名字的数据库
    @PostMapping("/doSave")
    public String doSave(String name){
        list.add(name);
        return "save ok";
    }

    @GetMapping("/doCheck")
    public String doCheck(String name){
        return list.contains(name)?name+"已存在":name+"可注册";
    }

    @CrossOrigin//此注解描述，让次url支持跨域
    @GetMapping("/doAjaxGet")//默认有斜杠，可以不写
    public String doAjaxGet()throws InterruptedException{
        System.out.println("==doAjaxGet==");
        //Thread.sleep(5000);
        return "Ajax Get Request Result";
    }
}
